<template>
  <el-card class="box-card">
    <!--查询-->
    <el-form
      :inline="true"
      class="demo-form-inline"
     
    >
      <el-form-item>
        <el-input v-model="title2" placeholder="姓名" size="small"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="query()"
          size="small"
          >查询</el-button
        >
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="reset()" size="small">重置</el-button>
      </el-form-item>
    </el-form>
    <!--表格-->
    <el-table
      :data="tableData"
      v-loading="loading"
      element-loading-text="拼命加载中"
      :border="true"
      style="width: 100%; margin: 0px 0px 20px 0px"
    >
      <el-table-column label="ID" prop="id" width="80"></el-table-column>
      <el-table-column label="姓名" prop="user"></el-table-column>
      <el-table-column label="职位" prop="position"></el-table-column>
      <el-table-column label="账号" prop="username"></el-table-column>
      <el-table-column label="登录城市" prop="city"></el-table-column>
      <el-table-column label="登录IP" prop="ip"></el-table-column>
      <el-table-column label="登录时间" prop="create_time">
        <template slot-scope="scope">
          {{scope.row.create_time|time}}
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </el-card>
</template>

<script>
import { get_list } from "@/api/login_log";
export default {
  name: "members",

  data() {
    return {
      title2: "",
      currentPage: 1,
      total: 1,
      page: 1,
      limit: 10,
      dialogVisible: false,
      loading: true,
      title: "添加会员",
      // 表格
      tableData: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    reset() {
      this.title2 = "";
      this.getList();
    },
    change() {
      this.$forceUpdate();
    },
    //分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
      this.getList();
    },
    //表格数据请求
    async getList() {
      this.loading = true;
      var data = await get_list({
        page: this.page,
        limit: this.limit,
        name: this.title2,
      });
      console.log(data);
      if (data.code == 20000) {
        this.loading = false;
        // console.log(data);
        this.tableData = data.data;
        this.total = data.total;
      }
    },
    query() {
      this.getList();
    },
  },
};
</script>

<style scoped>
.box-card {
  margin: 20px;
}
</style>